import 'package:flutter/material.dart';
import 'package:bip39/bip39.dart' as bip39;
import 'package:itoken/Components/CRouter.dart';

class PShowMnemonic extends StatelessWidget {
  final String mnemonic;
  PShowMnemonic({
    @required this.mnemonic,
  });
  _generateMnemonic() async {
    List<String> _mnemonic = mnemonic.split(" ");
    _mnemonic.sort();
    print(_mnemonic);
    CRouter.checkMnemonic(mnemonic: mnemonic, lists: _mnemonic);
    // String randomMnemonic = bip39.generateMnemonic();
    // print('助记词 ====> $randomMnemonic');
    // String seed = bip39.mnemonicToSeedHex(randomMnemonic);
    // KeyData master = ED25519_HD_KEY.getMasterKeyFromSeed(seed);
    // String privateKey = HEX.encode(master.key);
    // print('私钥 ====> $privateKey');
    // final private = EthPrivateKey.fromHex(privateKey);
    // final address = await private.extractAddress();
    // print('eth地址 ====> $address');
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("助记词展示"),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Container(
              padding: EdgeInsets.all(10),
              margin: EdgeInsets.all(10),
              decoration: BoxDecoration(
                border: Border.all(
                  color: Colors.red,
                ),
                borderRadius: BorderRadius.circular(6),
              ),
              child: Text(
                mnemonic,
                style: TextStyle(
                  fontSize: 16,
                ),
              ),
            ),
            RaisedButton(
              onPressed: _generateMnemonic,
              child: Text("我已记住"),
            )
          ],
        ),
      ),
    );
  }
}
